package com.sun.filesigndemo.common.pagehelper;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;


/**
* 对Page<E>结果进行包装
* <p/>
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class MyPageInfo<T> implements Serializable {
	
   private static final long serialVersionUID = 1L;
   //当前页
   private int page;

   //总记录数
   private long total;

    //每页的数量
    private int pageSize;
   
   //总页数
   private int pages;
   
   //结果集
   private List<T> list;

   public MyPageInfo() {
   }

   /**
    * 包装Page对象
    *
    * @param list          page结果
    */
   public MyPageInfo(List<T> list) {

       if (list instanceof Page) {
           Page page = (Page) list;
           this.page = page.getPageNum();
           
           this.list = page;
           this.total = page.getTotal();

           this.pages = page.getPages();
           this.pageSize = page.getPageSize();
          
       } else if (list instanceof Collection) {
	       this.page = 1;
	       
           this.pages = 1;
	       this.list = list;
	       this.total = list.size();
           this.pageSize = list.size();
       }
   }

   public int getPage() {
       return page;
   }

   public void setPage(int page) {
       this.page = page;
   }


   public long getTotal() {
       return total;
   }

   public void setTotal(long total) {
       this.total = total;
   }

   public List<T> getList() {
       return list;
   }

   public void setList(List<T> list) {
       this.list = list;
   }
   
   public int getPages() {
       return pages;
   }

   public void setPages(int pages) {
       this.pages = pages;
   }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

   @Override
   public String toString() {
       final StringBuffer sb = new StringBuffer("PageInfo{");
       sb.append("pageNum=").append(page);
       sb.append(", pageSize=").append(pageSize);
       sb.append(", pages=").append(pages);
       sb.append(", total=").append(total);
       sb.append(", list=").append(list);
       sb.append('}');
       return sb.toString();
   }
}

